#include "stdlib.h"
#include "stdio.h"
#include "string.h"
#include "typeDef.h"

#include "systemFun.h"
#include "netSocket.h"
#include "SetConfig.h"
#include "CLog.h"
#include <sstream>

static GINT32 configStrCmp(GINT8 *str1, GINT8 *str2)
{
	if (!str1 || !str2)
	{
		return 1;
	}

	while(*str1 == *str2)
	{
		if (!(*str1) || !(*str2))
		{
			break;
		}
		str1 ++;
		str2 ++;
	}

	if (!(*str1) || !(*str2))
	{
		return 0;
	}

	return 1;
}


static GUINT32 ReadStringFromTag(GINT8* pMemFile, GUINT32 memFileLen, GINT8 *pTag, GINT8 *pBuf, GUINT32 bufLen)
{
	GINT8 *pStart;
	GINT8 *pEnd;
	GINT8 *pCu;

	pCu = strstr(pMemFile, pTag);
	if (!pCu)
	{
		return 0;
	}

	pCu += strlen(pTag);
	if (configStrCmp(pCu, "\r\n") == 0)
	{
		pCu+=2;
	}
	else if (configStrCmp(pCu, "\n") == 0)
	{
		pCu+=1;
	}
	else
	{
		return 0;
	}

	pStart = pCu;

	pCu = strstr(pStart, "[");
	if (!pCu)
	{
		DOUT("no find '['\r\n");
		return 0;
	}

	pEnd = pCu;

	if ((GUINT32)(pEnd - pStart) >= (bufLen -1 ))
	{
		return 0;
	}

	memcpy(pBuf, pStart, pEnd-pStart);

	pBuf[pEnd-pStart] = 0;

	return (pEnd-pStart)+1;
}



static CSetConfig m_gDbConfig;

CSetConfig* CSetConfig::GetInstance()
{
    return &m_gDbConfig;
}   
    

CSetConfig::CSetConfig()
{
	m_canUse      = TFALSE;
}

CSetConfig::~CSetConfig()
{

}

STATUS CSetConfig::Close()
{
    return RE_SUCCEED;
}


STATUS CSetConfig::PaserConfig()
{
    return RE_SUCCEED;
fail:
	return RE_FAIL;
}
